package com.changgou.service.impl;

import com.changgou.bean.BG_SYTP;
import com.changgou.bean.PageResult;
import com.changgou.mapper.syMapper;
import com.changgou.service.syService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import entity.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;
import java.util.Map;

@Service
public class syServiceImpl implements syService {

    @Resource
    private syMapper syMapper;

    @Override
    public PageResult getblogtp(Map<String, Object> map) {
        PageHelper.startPage((int) map.get("page"), (int) map.get("limit"));
        List<BG_SYTP> bg_sytps = syMapper.getblogtp(map);
        PageInfo<BG_SYTP> info = new PageInfo<BG_SYTP>(bg_sytps);
        PageResult pageResult = new PageResult(info.getTotal(), info.getList(), null, 200);
        return pageResult;
    }

    @Override
    public boolean addblogtp(Map<String, Object> map) {
        IdWorker img_id = new IdWorker(0,0);
        map.put("img_id",img_id);
        return  syMapper.addblogtp(map);
    }

    @Override
    public boolean delbolgtp(Map<String, Object> map) {
        List<String> lis = (List<String>) map.get("fileurl");
        boolean od = false;
        for (int i = 0; i<lis.size(); i++) {
            od = new File(lis.get(i)).delete();
        }
        return  syMapper.delbolgtp(map);
    }
}
